home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / www / library / implemen / htalert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  3.0 KB  |  121 lines

  1. /*    Displaying messages and getting input for LineMode Browser
  2. **    ==========================================================
  3. **
  4. **    REPLACE THIS MODULE with a GUI version in a GUI environment!
  5. **
  6. ** History:
  7. **       Jun 92 Created May 1992 By C.T. Barker
  8. **       Feb 93 Simplified, portablised TBL
  9. **       Sep 93 Corrected 3 bugs in HTConfirm() :-( AL
  10. */
  11.  
  12.  
  13. #include"capalloc.h"
  14. #include"capstdio.h"
  15. #include "HTAlert.h"
  16.  
  17. #include "tcp.h"        /* for TOUPPER */
  18. #include <ctype.h>         /* for toupper - should be in tcp.h */
  19.  
  20. PUBLIC void HTAlert ARGS1(CONST char *, Msg)
  21. {
  22. #ifdef NeXTStep
  23.     NXRunAlertPanel(NULL, "%s", NULL, NULL, NULL, Msg);
  24. #else
  25.     fprintf(stderr, "WWW Alert:  %s\n", Msg);
  26. #endif
  27. }
  28.  
  29.  
  30. PUBLIC void HTProgress ARGS1(CONST char *, Msg)
  31. {
  32.     fprintf(stderr, "   %s ...\n", Msg);
  33. }
  34.  
  35.  
  36. PUBLIC BOOL HTConfirm ARGS1(CONST char *, Msg)
  37. {
  38.   char Reply[4];    /* One more for terminating NULL -- AL */
  39.   char *URep;
  40.   
  41.   fprintf(stderr, "WWW: %s (y/n) ", Msg);
  42.                        /* (y/n) came twice -- AL */
  43.  
  44.   fgets(Reply, 4, stdin); /* get reply, max 3 characters */
  45.   URep=Reply;
  46.   while (*URep) {
  47.     if (*URep == '\n') {
  48.     *URep = (char)0;    /* Overwrite newline */
  49.     break;
  50.     }
  51.     *URep=TOUPPER(*URep);
  52.     URep++;    /* This was previously embedded in the TOUPPER */
  53.                 /* call an it became evaluated twice because   */
  54.                 /* TOUPPER is a macro -- AL */
  55.   }
  56.  
  57.   if ((strcmp(Reply,"YES")==0) || (strcmp(Reply,"Y")==0))
  58.     return(YES);
  59.   else
  60.     return(NO);
  61. }
  62.  
  63. /*    Prompt for answer and get text back
  64. */
  65. PUBLIC char * HTPrompt ARGS2(CONST char *, Msg, CONST char *, deflt)
  66. {
  67.     char Tmp[200];
  68.     char * rep = 0;
  69.     fprintf(stderr, "WWW: %s", Msg);
  70.     if (deflt) fprintf(stderr, " (RETURN for [%s]) ", deflt);
  71.     
  72.     fgets(Tmp, 200, stdin);
  73.     Tmp[strlen(Tmp)-1] = (char)0;    /* Overwrite newline */
  74.    
  75.     StrAllocCopy(rep, *Tmp ? Tmp : deflt);
  76.     return rep;
  77. }
  78.  
  79.  
  80. /*    Prompt for password without echoing the reply
  81. */
  82. PUBLIC char * HTPromptPassword ARGS1(CONST char *, Msg)
  83. {
  84.     char *result = NULL;
  85.     char *pw = (char*)getpass(Msg ? Msg : "Password: ");
  86.  
  87.     StrAllocCopy(result, pw);
  88.     return result;
  89. }
  90.  
  91.  
  92. /*    Prompt both username and password    HTPromptUsernameAndPassword()
  93. **    ---------------------------------
  94. ** On entry,
  95. **    Msg        is the prompting message.
  96. **    *username and
  97. **    *password    are char pointers; they are changed
  98. **            to point to result strings.
  99. **
  100. **            If *username is not NULL, it is taken
  101. **            to point to  a default value.
  102. **            Initial value of *password is
  103. **            completely discarded.
  104. **
  105. ** On exit,
  106. **    *username and *password point to newly allocated
  107. **    strings -- original strings pointed to by them
  108. **    are NOT freed.
  109. **    
  110. */
  111. PUBLIC void HTPromptUsernameAndPassword ARGS3(CONST char *,    Msg,
  112.                           char **,        username,
  113.                           char **,        password)
  114. {
  115.     if (Msg)
  116.     fprintf(stderr, "WWW: %s\n", Msg);
  117.     *username = HTPrompt("Username: ", *username);
  118.     *password = HTPromptPassword("Password: ");
  119. }
  120.  
  121.